﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenericLibrariesToolKit
{
    /// <summary>
    /// 实体管理器工厂类，用于创建实体管理器
    /// </summary>
    public class EntityManagerFactory
    {
        //实体管理器扫描路径
        private static string scanPath;

        //单例模式实现代码
        #region
        /// <summary>
        /// 私有构造函数
        /// </summary>
        private EntityManagerFactory() { }

        /// <summary>
        /// 创建一个实体管理器工厂类
        /// </summary>
        /// <param name="inputScanPath">实体管理器扫描路径</param>
        /// <returns>实体管理器工厂类对象</returns>
        public static EntityManagerFactory CreateEntityManagerFactory(string inputScanPath)
        {
            scanPath = inputScanPath;
            return EntityManagerFactoryHolder.instance;
        }

        /// <summary>
        /// 类级内部类
        /// </summary>
        private static class EntityManagerFactoryHolder
        {
            //保证线程安全
            public static EntityManagerFactory instance = new EntityManagerFactory();
        }
        #endregion

        /// <summary>
        /// 创建一个实体管理器
        /// </summary>
        /// <returns></returns>
        public EntityManager CreateEntityManager()
        {
            //将扫描路径赋给实体管理器
            EntityManager.scanPath = scanPath;
            return EntityManager.CreateEntityManager();
        }
    }
}
